//package com.统一多个类的接口设计.design.patterns.geekbang.创建型.单例模式.替代方案.集群唯一;
//
//import java.util.concurrent.atomic.AtomicLong;
//
//public class IdGenerator {
//    private AtomicLong id = new AtomicLong(0);
//    private static IdGenerator instance;
//    private static SharedObjectStorage storage = FileSharedObjectStorage(/*入参省略，比如文件地址*/);
//    private static DistributedLock lock = new DistributedLock();
//
//    private IdGenerator() {
//    }
//
//    public synchronized static IdGenerator getInstance() {
//        if (instance == null) {
//            lock.lock();
//            instance = storage.load(IdGenerator.class);
//        }
//        return instance;
//    }
//
//    public synchronized void freeInstance() {
//        storage.save(this, IdGeneator.class);
//        instance = null; //释放对象 
//        lock.unlock();
//    }
//
//    public long getId() {
//        return id.incrementAndGet();
//    }
//}
